* ====================================================================================================================================
* Paper title: Taking a gamble: Chinese overseas energy finance and country risk
* Authors: Hanna Niczyporuk (NYU) and Johannes Urpelainen (JOHNS HOPKINS SAIS) 

* Last modified: December 6, 2020

* Data files used:
*chinamdb_noniv.dta
*nonchina_noniv.dta
*chinanonchina_mdb_iv.dta
*

* Purpose: This do file replicates the results presented in the main text of the paper 
* Remark: Please set up your working directory before replicating the results
cd "~/workingdirectory"

* ====================================================================================================================================

*Table 1: Energy finance by MDBs (2005–2017)

* ====================================================================================================================================

*Please see R replication file

* ====================================================================================================================================

*Table 2: Hurdle Model: Investment by Chinese MDBs (2005–2017)

* ====================================================================================================================================

use "/workingdirectory/chinamdb_noniv.dta"

*Create globals

global wgi "political_stability_rounded corruption_rounded gov_effectiveness_rounded"
global economy " fdi_inflows_percgdp_0004mean log_gdppc log_population"
global economy_small " fdi_inflows_percgdp_0004mean log_population"
global energy "log_coalproduction_0004mean log_oilproduction_0004mean log_gasproduction_0004mean"

encode country, gen(countryid)
xtset countryid year


*Model 1

xi: churdle linear log_chinafunding rank_norm t t2 t3 i.region_wb, ///
select(rank_norm)  ll(0) vce(cluster countryid)
outreg2 using "table2.xls" , excel  replace se label par dec(2) bdec(3) tdec(3) ///
addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes ///
addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 2

xi: churdle linear log_chinafunding rank_norm auto_bin t t2 t3 i.region_wb, ///
select(rank_norm auto_bin)  ll(0) vce(cluster countryid)
outreg2 using "table2.xls" , excel append se label par dec(2) bdec(3) tdec(3) ///
addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes ///
addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 3

xi: churdle linear log_chinafunding rank_norm $wgi t t2 t3 i.region_wb, ///
select(rank_norm $wgi)  ll(0) vce(cluster countryid)
outreg2 using "table2.xls" , excel append se label par dec(2) bdec(3) tdec(3) ///
addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes ///
addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 4

xi: churdle linear log_chinafunding rank_norm auto_bin $wgi t t2 t3 i.region_wb, ///
select(rank_norm auto_bin $wgi)  ll(0) vce(cluster countryid)
outreg2 using "table2.xls" , excel append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 5

xi: churdle linear log_chinafunding rank_norm $economy $energy t t2 t3 i.region_wb, ///
select(rank_norm $economy $energy)  ll(0) vce(cluster countryid)
outreg2 using "table2.xls" , excel append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 6

xi: churdle linear log_chinafunding rank_norm auto_bin $economy $energy  t t2 t3 i.region_wb, ///
select(rank_norm auto_bin $economy $energy) ll(0) vce(cluster countryid)
outreg2 using "table2.xls" , excel append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 7

xi: churdle linear log_chinafunding rank_norm $wgi $economy $energy t t2 t3 i.region_wb, ///
select(rank_norm $wgi $economy $energy) ll(0) vce(cluster countryid)
outreg2 using "table2.xls" , excel append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 8

xi: churdle linear log_chinafunding rank_norm auto_bin $wgi $economy $energy t t2 t3 i.region_wb, ///
select(rank_norm auto_bin $wgi $economy $energy) ll(0) vce(cluster countryid)
outreg2 using "table2.xls" , excel append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")


*************************************** Marginal effects ****************************************


*Model 1
probit log_chinafunding rank_norm, vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table2_margins.xls" , excel replace se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")
	
*Model 2
probit log_chinafunding rank_norm auto_bin,vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table2_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")
	
*Model 3
probit log_chinafunding rank_norm $wgi, vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table2_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")
	
*Model 4	

probit log_chinafunding rank_norm auto_bin $wgi, vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table2_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")

*Model 5

probit log_chinafunding rank_norm $economy $energy , vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table2_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")

*Model 6
probit log_chinafunding rank_norm auto_bin $economy $energy , vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table2_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")

*Model 7
probit log_chinafunding rank_norm $wgi $economy $energy , vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table2_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")

*Model 8
probit log_chinafunding rank_norm auto_bin $wgi $economy $energy , vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table2_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")


* ====================================================================================================================================

*Table 3: Hurdle Model: Investment by Non-Chinese MDBs (2005–2017)

* ====================================================================================================================================


use "/workingdirectory/nonchina_noniv.dta"

*Create globals


global wgi "political_stability_rounded corruption_rounded gov_effectiveness_rounded"
global economy " fdi_inflows_percgdp_0004mean log_gdppc log_population"
global economy_small " fdi_inflows_percgdp_0004mean log_population"
global energy "log_coalproduction_0004mean log_oilproduction_0004mean log_gasproduction_0004mean"

encode country, gen(countryid)
xtset countryid year

*Model 1

xi: churdle linear log_nonchinafunding rank_norm t t2 t3 i.region_wb, ///
select(rank_norm)  ll(0) vce(cluster countryid)
outreg2 using "table3.xls" , excel  replace se label par dec(2) bdec(3) tdec(3) ///
addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes ///
addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 2

xi: churdle linear log_nonchinafunding rank_norm auto_bin t t2 t3 i.region_wb, ///
select(rank_norm auto_bin)  ll(0) vce(cluster countryid)
outreg2 using "table3.xls" , excel append se label par dec(2) bdec(3) tdec(3) ///
addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes ///
addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 3

xi: churdle linear log_nonchinafunding rank_norm $wgi t t2 t3 i.region_wb, ///
select(rank_norm $wgi)  ll(0) vce(cluster countryid)
outreg2 using "table3.xls" , excel append se label par dec(2) bdec(3) tdec(3) ///
addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes ///
addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 4

xi: churdle linear log_nonchinafunding rank_norm auto_bin $wgi t t2 t3 i.region_wb, ///
select(rank_norm auto_bin $wgi)  ll(0) vce(cluster countryid)
outreg2 using "table3.xls" , excel append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 5

xi: churdle linear log_nonchinafunding rank_norm $economy $energy t t2 t3 i.region_wb, ///
select(rank_norm $economy $energy)  ll(0) vce(cluster countryid)
outreg2 using "table3.xls" , excel append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 6

xi: churdle linear log_nonchinafunding rank_norm auto_bin $economy $energy  t t2 t3 i.region_wb, ///
select(rank_norm auto_bin $economy $energy) ll(0) vce(cluster countryid)
outreg2 using "table3.xls" , excel append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 7

xi: churdle linear log_nonchinafunding rank_norm $wgi $economy $energy t t2 t3 i.region_wb, ///
select(rank_norm $wgi $economy $energy) ll(0) vce(cluster countryid)
outreg2 using "table3.xls" , excel append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")

*Model 8

xi: churdle linear log_nonchinafunding rank_norm auto_bin $wgi $economy $energy t t2 t3 i.region_wb, ///
select(rank_norm auto_bin $wgi $economy $energy) ll(0) vce(cluster countryid)
outreg2 using "table3.xls" , excel append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")



*************************************** Marginal effects ****************************************


*Model 1
probit log_nonchinafunding rank_norm, vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table3_margins.xls" , excel replace se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")
	
*Model 2
probit log_nonchinafunding rank_norm auto_bin,vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table3_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")
	
*Model 3
probit log_nonchinafunding rank_norm $wgi, vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table3_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")
	
*Model 4	

probit log_nonchinafunding rank_norm auto_bin $wgi, vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table3_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")

*Model 5

probit log_nonchinafunding rank_norm $economy $energy , vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table3_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")

*Model 6
probit log_nonchinafunding rank_norm auto_bin $economy $energy , vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table3_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")

*Model 7
probit log_nonchinafunding rank_norm $wgi $economy $energy , vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table3_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")

*Model 8
probit log_nonchinafunding rank_norm auto_bin $wgi $economy $energy , vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table3_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")


* ====================================================================================================================================

*Table 4: Hurdle Models: Effects of the Credit Rating on the Investment by the Chinese and non-Chinese MDBs (2005–2017)

* ====================================================================================================================================

*Model 1

xi: churdle linear log_chinafunding i.rank auto_bin $wgi $economy $energy t t2 t3 i.region_wb, ///
select(i.rank auto_bin $wgi $economy $energy) ll(0) vce(cluster countryid)
outreg2 using "table4.xls" , replace append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")


*Model 2


xi: churdle linear log_nonchinafunding i.rank auto_bin $wgi $economy $energy t t2 t3 i.region_wb, ///
select(i.rank auto_bin $wgi $economy $energy) ll(0) vce(cluster countryid)
outreg2 using "table4.xls" , append append se label par dec(2) bdec(3) tdec(3) addstat("Countries", e(N_clust), "Pseudo R2", e(r2_p)) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "All models include region fixed effects and linear, quadratic and cubic time trends." "*p<.05; **p<.01; ***p<.001")



*************************************** Marginal effects ****************************************

*Model 1


probit log_chinafunding creditrank_d_2 creditrank_d_3 creditrank_d_4 creditrank_d_5 creditrank_d_6 creditrank_d_7 creditrank_d_8 auto_bin $wgi $economy $energy , vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table4_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")

*Model 2

probit log_nonchinafunding creditrank_d_2 creditrank_d_3 creditrank_d_4 creditrank_d_5 creditrank_d_6 creditrank_d_7 creditrank_d_8 auto_bin $wgi $economy $energy , vce(cluster countryid)
margins, dydx(*) atmeans post
outreg2 using "table4_margins.xls" , excel append se label par dec(2) bdec(3) tdec(3) symbol(***, **, *) drop(t* _Iregion_*) nonotes addnote("Dependent Variable: Funding amount (log + 1). Standard errors in parentheses and clustered by country." "*p<.05; **p<.01; ***p<.001")

* ====================================================================================================================================

*Table 5: Simultaneous Probit Model: Investment by Chinese MDBs (2005–2017)

* ====================================================================================================================================


clear all
set more off, permanently
cd "~/workingdirectory"
use "/workingdirectory/chinanonchina_mdb_iv.dta"

*Create globals


global wgi "political_stability_rounded corruption_rounded gov_effectiveness_rounded"
global economy " fdi_inflows_percgdp_0004mean log_gdppc log_population"
global economy_small "fdi_inflows_percgdp_0004mean log_population"
global energy "log_coalproduction_0004mean log_oilproduction_0004mean log_gasproduction_0004mean"

encode country, gen(countryid)
xtset countryid year

*Model 1

biprobit (china_invested = nonchina_invested rank_norm) (nonchina_invested = log_nonchin_totproj_n_0004mean rank_norm), robust
outreg2 using "table5.xlsx" , excel  replace se label par dec(2) bdec(3) tdec(3) 

margins, dydx(nonchina_invested rank_norm) predict(pmarg1) force post
outreg2 using "table5_margins.xlsx" , excel  replace se label par dec(2) bdec(3) tdec(3) 

*Model 2:

biprobit (china_invested = nonchina_invested rank_norm auto_bin) (nonchina_invested = log_nonchin_totproj_n_0004mean rank_norm auto_bin), robust
outreg2 using "table5.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(nonchina_invested rank_norm auto_bin) predict(pmarg1) force post
outreg2 using "table5_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 3:

biprobit (china_invested = nonchina_invested rank_norm $wgi) (nonchina_invested = log_nonchin_totproj_n_0004mean rank_norm $wgi) , robust
outreg2 using "table5.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(nonchina_invested rank_norm $wgi) predict(pmarg1) force post
outreg2 using "table5_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 4: 

biprobit (china_invested = nonchina_invested rank_norm $wgi auto_bin) (nonchina_invested = log_nonchin_totproj_n_0004mean rank_norm $wgi) , robust
outreg2 using "table5.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(nonchina_invested rank_norm $wgi auto_bin) predict(pmarg1) force post
outreg2 using "table5_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 5:


biprobit (china_invested = nonchina_invested rank_norm $economy $energy) (nonchina_invested = log_nonchin_totproj_n_0004mean rank_norm $economy $energy) , robust
outreg2 using "table5.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(nonchina_invested rank_norm $economy $energy) predict(pmarg1) force post
outreg2 using "table5_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 6:

biprobit (china_invested = nonchina_invested rank_norm auto_bin $economy $energy) (nonchina_invested = log_nonchin_totproj_n_0004mean rank_norm $economy $energy) , robust
outreg2 using "table5.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(nonchina_invested rank_norm auto_bin $economy $energy) predict(pmarg1) force post
outreg2 using "table5_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 7:

biprobit (china_invested = nonchina_invested rank_norm  $wgi $economy $energy) (nonchina_invested = log_nonchin_totproj_n_0004mean auto_bin $wgi $economy $energy )
outreg2 using "table5.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(nonchina_invested rank_norm   $wgi $economy $energy) predict(pmarg1) force post
outreg2 using "table5_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 8:

biprobit (china_invested = nonchina_invested rank_norm auto_bin $wgi $economy $energy) (nonchina_invested = log_nonchin_totproj_n_0004mean auto_bin $wgi $economy $energy )
outreg2 using "table5.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(nonchina_invested rank_norm auto_bin  $wgi $economy $energy) predict(pmarg1) force post
outreg2 using "table5_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 


* ====================================================================================================================================

*Table 6: Simultaneous Probit Model: Investment by non-Chinese MDBs (2005–2017)

* ====================================================================================================================================


clear all
set more off, permanently
cd "~/workingdirectory"
use "/workingdirectory/chinanonchina_mdb_iv.dta"

*Create globals


global wgi "political_stability_rounded corruption_rounded gov_effectiveness_rounded"
global economy " fdi_inflows_percgdp_0004mean log_gdppc log_population"
global economy_small "fdi_inflows_percgdp_0004mean log_population"
global energy "log_coalproduction_0004mean log_oilproduction_0004mean log_gasproduction_0004mean"

encode country, gen(countryid)
xtset countryid year

*Model 1


biprobit (nonchina_invested = china_invested rank_norm) (china_invested = log_chinaimports_0004mean rank_norm), robust
outreg2 using "table6.xlsx" , excel  replace se label par dec(2) bdec(3) tdec(3) 

margins, dydx(china_invested rank_norm) predict(pmarg1) force post
outreg2 using "table6_margins.xlsx" , excel  replace se label par dec(2) bdec(3) tdec(3) 


*Model 2

biprobit (nonchina_invested = china_invested rank_norm auto_bin) (china_invested = log_chinaimports_0004mean rank_norm auto_bin), robust
outreg2 using "table6.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(china_invested rank_norm auto_bin) predict(pmarg1) force post
outreg2 using "table6_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 


*Model 3

biprobit (nonchina_invested = china_invested rank_norm $wgi) (china_invested = log_chinaimports_0004mean rank_norm $wgi) , robust
outreg2 using "table6.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(china_invested rank_norm $wgi) predict(pmarg1) force post
outreg2 using "table6_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 4


biprobit (nonchina_invested = china_invested rank_norm auto_bin $wgi) (china_invested = log_chinaimports_0004mean rank_norm $wgi) , robust
outreg2 using "table6.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(china_invested rank_norm auto_bin $wgi) predict(pmarg1) force post
outreg2 using "table6_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 5


biprobit (nonchina_invested = china_invested rank_norm $economy $energy) (china_invested = log_chinaimports_0004mean rank_norm $economy $energy) , robust
outreg2 using "table6.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(china_invested rank_norm $economy $energy) predict(pmarg1) force post
outreg2 using "table6_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 6

biprobit (nonchina_invested = china_invested rank_norm auto_bin $economy $energy) (china_invested = log_chinaimports_0004mean rank_norm $economy $energy) , robust
outreg2 using "table6.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(china_invested rank_norm auto_bin $economy $energy) predict(pmarg1) force post
outreg2 using "table6_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 7

biprobit (nonchina_invested = china_invested rank_norm $wgi $economy $energy) (china_invested = log_chinaimports_0004mean rank_norm $wgi $economy $energy), robust
outreg2 using "table6.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(china_invested rank_norm $wgi $economy $energy) predict(pmarg1) force post
outreg2 using "table6_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

*Model 8

biprobit (nonchina_invested = china_invested rank_norm auto_bin $wgi $economy $energy) (china_invested = log_chinaimports_0004mean rank_norm $wgi $economy $energy), robust
outreg2 using "table6.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

margins, dydx(china_invested rank_norm auto_bin $wgi $economy $energy) predict(pmarg1) force post
outreg2 using "table6_margins.xlsx" , excel  append se label par dec(2) bdec(3) tdec(3) 

